<?
include("session.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>电销助手外呼</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../../../webkit/grid/import.js"></script>
<script type="text/javascript" src="../../../webkit/dialog/import.js"></script>
</head>
<body bgccolor="#f4f4f4" style="margin:0px;overflow-x:hidden">

<table width=100% height=100% cellspacing=0 cellpadding=0>
	<tr bgcolor="white">
	<form name=f>
	<td height=30>　
		业务类型：<select id="biz_type" class='input'><option value=''>-请选择-</option><option value='1'>集团彩铃</option><option value='2'>基地业务</option></select>　
		<input type="button" value="查询" onclick="search()">　
	</td>
	</tr>
	<tr>
	<td>
		<table id="flex1" style="display:none"></table>
	</td>
	</form>
	</tr>
</table>


<script>
	var agent_id = "<?echo $_SESSION['hngj_agent_id']?>";

	var h = window.screen.height-430; // 属于嵌入外部url，只能按screen高度大致计算
	//alert(h)
	if(h < 0) h = 'auto'
	$("#flex1").flexigrid({
		url: 'task_query.php?action=list',
		dataType: 'json',
		colModel : [
			{display: 'ID', name : 'a', width : 30, sortable : false, align: 'center'},
			{display: '任务名称', name : 'a', width : 170, sortable : false, align: 'center'},
			{display: '业务类型', name : 'a', width : 60, sortable : false, align: 'center'},
			{display: '外显号码', name : 'b', width : 70, sortable : false, align: 'center'},
			{display: '号码总数', name : 'call_count', width : 50, sortable : true, align: 'center'},
			{display: '可分配数', name : 'free_count', width : 50, sortable : true, align: 'center'},
			{display: '营销成功', name : 'success_count', width : 50, sortable : true, align: 'center'},
			{display: '成功率', name : 'success_rate', width : 40, sortable : true, align: 'center'},
			{display: '营销失败', name : 'fail_count', width : 50, sortable : true, align: 'center'},
			{display: '预约回拔', name : 'appt_count', width : 50, sortable : false, align: 'center'},
			{display: '其它结果', name : 'other_count', width : 50, sortable : false, align: 'center'},
			{display: '任务状态', name : 'c', width : 160, sortable : false, align: 'center'},
			{display: '最近外呼', name : 'b', width : 120, sortable : false, align: 'center'},
			{display: '创建时间', name : 'b', width : 120, sortable : false, align: 'center'},
			{display: '营销模板', name : 'c', width : 60, sortable : false, align: 'center'}
			],
		buttons : [
			{name: '新增', bclass: 'add', onpress : add},
			{name: '修改', bclass: 'edit', onpress : edit},
			{name: '删除', bclass: 'del', onpress : del},
			{separator: true},
            {name: '导入外呼号码', bclass: 'add', onpress : import_data},
			{name: '清空导入号码', bclass: 'del', onpress : clear_data},
			{name: '导入营销模板', bclass: 'tool', onpress : import_text},
			{separator: true},
            {name: '清除剩余号码', bclass: 'del', onpress : clear_free_data},
			{name: '暂停任务', bclass: 'other', onpress : pause_task},
			{name: '启动任务', bclass: 'start', onpress : start_task}
		],
		async : true,
		usepager: true,
		title: '任务管理',
		useRp: true,
		rp: 8,
		showTableToggleBtn: false,
		width: 'auto',
		height: h,
		resizable : false,
		singleSelect : true,
		onSuccess : function() {show_sum_total("4,5,6,8,9,10,")}
	});

	<?
	$add_url = "task_panel.php?op=add";
	$edit_url = "task_panel.php?op=edit&id="; 
	$del_url = "task_query.php?action=del&id=";
	$dlg_size = "500, 200";
	require("../../grid_common_js.php");
	?>

    $('#flex1').dblclick( function (e) { 
        select_row_on_dblclick(e);
        edit();
    });

	function search() { 
		var url = "task_query.php?action=list";
         if($("#biz_type").val()!="") {
            url += "&biz_type="+ $("#biz_type").val();
        }        
		$('#flex1').flexOptions({'url': url}).flexReload(); 
	}

	function show_text(f) {
		dlg = new Dialog({ title: '查看营销模板', resizable:false, maximizable:false}).href("text/"+f);
		dlg.show().setSize(520, 320).center();
	}

	function show_agent_score(task_id) {
		dlg = new Dialog({ title: '任务排名统计', resizable:false, maximizable:false}).href("agent_score_list.php?task_id="+task_id);
		dlg.show().setSize(650, 300).center();
	}


	function import_data(id) {
	   if(isNaN(id)) {
			id = $("#flex1").getSelectedRowId();
	   }
	   if(id == -1) {
		   alert("请选择一条记录进行操作！");
		   return false;
	   }
		dlg = new Dialog({ title: '导入外呼号码', resizable:false, maximizable:false}).href("call_import.php?task_id="+id);
		dlg.show().setSize(520, 130).center();
	}

	function import_text(id) {
	   if(isNaN(id)) {
			id = $("#flex1").getSelectedRowId();
	   }
	   if(id == -1) {
		   alert("请选择一条记录进行操作！");
		   return false;
	   }
		dlg = new Dialog({ title: '导入营销模板', resizable:false, maximizable:false}).href("text_import.php?task_id="+id);
		dlg.show().setSize(520, 130).center();
	}


	function set_back(task_id) {
		dlg = new Dialog({ title: '回收营销任务', resizable:false, maximizable:false}).href("task_back_list.php?task_id="+task_id);
		dlg.show().setSize(520, 220).center();
	}

	function show_import_batch(task_id) {
		dlg = new Dialog({ title: '任务导入批次', resizable:false, maximizable:false}).href("task_import_list.php?task_id="+task_id);
		dlg.show().setSize(520, 220).center();
	}

	function clear_data() {
		var id = $("#flex1").getSelectedRowId();
		if(isNaN(id) || id<1) {
			alert("请选择一条有效记录！");
			return false;
		}
		if(confirm("确认要清空导入号码吗?")) {
			$.get("task_query.php?action=clear_data&task_id="+id, function(data){
				if(data == "ok") {
					alert("操作成功！");
					refreshGrid();
				} else {
					alert(data);	
				}
			});
		}
	}

	function dispatch_task(id) {
		dlg = new Dialog({ title: '分配营销任务', resizable:false, maximizable:false}).href("task_dispatch.php?task_id="+id);
		dlg.show().setSize(520, 300).center();
	}

	function clear_free_data() {
		var id = $("#flex1").getSelectedRowId();
		if(isNaN(id) || id<1) {
			alert("请选择一条有效记录！");
			return false;
		}
		if(confirm("确认要清空未分配的剩余数据吗?")) {
			$.get("task_query.php?action=clear_free_data&task_id="+id, function(data){
				if(data == "ok") {
					alert("操作成功！");
					refreshGrid();
				} else {
					alert(data);	
				}
			});
		}
	}
	

	function start_task() {
		var id = $("#flex1").getSelectedRowId();
		if(isNaN(id) || id<1) {
			alert("请选择一条有效记录！");
			return false;
		}
		if(confirm("确认要启动任务吗?")) {
			$.get("task_query.php?action=set_task_run_flag&flag=start&task_id="+id, function(data){
				if(data == "ok") {
					alert("操作成功！");
					refreshGrid();
				} else {
					alert(data);	
				}
			});
		}
	}


	function pause_task() {
		var id = $("#flex1").getSelectedRowId();
		if(isNaN(id) || id<1) {
			alert("请选择一条有效记录！");
			return false;
		}
		if(confirm("确认要暂停任务吗?")) {
			$.get("task_query.php?action=set_task_run_flag&flag=pause&task_id="+id, function(data){
				if(data == "ok") {
					alert("操作成功！");
					refreshGrid();
				} else {
					alert(data);	
				}
			});
		}
	}
</script>
</body>
</html>